<script>
    function checkUpdate() {
        const updateManager = uni.getUpdateManager();

        updateManager.onCheckForUpdate(function (res) {
            console.log('onCheckForUpdate', res.hasUpdate);
        });

        updateManager.onUpdateReady(function () {
            uni.showModal({
                title: '更新提示',
                content: '小程序有新版本，是否重启并更新？',
                success(res) {
                    if (res.confirm) {
                        updateManager.applyUpdate();
                    }
                }
            });
        });

        updateManager.onUpdateFailed(function () {
            console.error('onUpdateFailed');
        });
    }

    export default {
        async onLaunch() {
            await this.$store.dispatch('user/gatherDeviceInfo');
            // 获取用户信息
            await this.$store.dispatch('user/updateUserInfo');
            // 检查更新
            await checkUpdate();
        }
    };
</script>

<style lang="scss">
@import "~uview-ui/index.scss";
.content {
    min-height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}
</style>
